﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           var sql = "select * from Users";
           var dt = DbHelp.AddOrUpdate(sql);
        }
        //登录
        protected void tbLogin_Click(object sender, EventArgs e)
        {
            var userName = tbusername.Text.Trim();
            var passWord = tbpassword.Text.Trim();

            var sql = string.Format("select * from Users where Username='{0}'", userName);
            var dt = DbHelp.GetData(sql);

            if (dt.Rows.Count == 1)
            {

                var item = dt.Rows[0];

                var isActived = (bool)item.ItemArray[3];
                var isDelete = (bool)item.ItemArray[4];
                var pwd = item.ItemArray[2].ToString();
                if (isDelete)
                {
                    Response.Write("账号已被删除，如有疑问,请拨打114咨询");
                }
                else
                {
                    if (isActived)
                    {
                        if (passWord == pwd)
                        {
                            Response.Redirect("Default.aspx");
                            Response.Write("登录成功");

                        }
                        else
                        {
                            Response.Write("密码错误");
                        }
                    }
                    else
                    {
                        Response.Write("账号已过期或已被冻结,如有疑问,请拨打114咨询");
                    }
                }
            }
            else
            {
                Response.Write("账号不存在");
            }

        }
        //注册
        protected void tbRegister_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }
    }
}